﻿#ifndef OPDB_H
#define OPDB_H

#include <QObject>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QList>
#include <QTime>
#include <QPair>
#include "mypdu.h"

class OpDb : public QObject
{
    Q_OBJECT
public:
    explicit OpDb(QObject *parent = nullptr);
    ~OpDb();
    static OpDb& getInstance();
    void  connectDB();
    bool  addUser(userInfo u,int& id,const char* buff);//注册使用
    bool  selectUser(userInfo u);//登录使用
    void  handlerLogOut(userInfo u);//处理下线
    int  isOnline(QString uid);//查询用户是否在线
    QList<userInfo> selectOnlineFriend(userInfo u);//查找此用户的好友
    QList<QString> selectGroup(QString uname);//查找此用户的群聊
    bool  handleAddFriend(const char *name);
    void  addFriend(const char *name1,const char *name2);//答应后添加好友
    QString getUserInfo(QString name);
    QString getUserHead(QString name);
    bool  ResetPwd(PDU* pdu);
    QString  handlerFindPwd(QString username);
    bool registerGroup(QString groupname,QString& groupid,userInfo& u);
    QString getGroupHead(QString groupid);//获取群头像
    QString getGroupName(QString groupid);//获取群名称
    void addFriendToGroup(QString uid,QString gid);
    QList<QPair<QString,int>> getGroupPerson(QString gid);
    void updateGroupNotify(QString msg,QString gid);
signals:

private:
    QSqlDatabase m_db;
};

#endif // OPDB_H
